package org.leiyang.common.service;

import org.springframework.web.reactive.function.client.WebClient;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 非Feign方式的远程调用
 */
public class RemoteCall {

    /**
     * 缓存WebClient 格式: key=>serverIpPort
     */
    Map<String, WebClient> webClientMap = new ConcurrentHashMap<>();

    /**
     * 获取缓存的WebClient
     */
    public WebClient gotCahcedWebClient(String serverIpPort) {
        return webClientMap.computeIfAbsent(serverIpPort, k -> WebClient.builder()
                .baseUrl("http://".concat(serverIpPort))
                .build());
    }
}